import os
import sys

#获取指定目录的路径
dirsrc='D:\\大讲堂\\3.linux应用编程和网络编程（已完结）'
dirsrc2='D:\\大讲堂\\2.uboot和系统移植'
dirsrc3='D:\\大讲堂\\1.ARM裸机全集'
tot=0

for root,dirs,files in os.walk(dirsrc,topdown=True):
    print(root,dirs,flush=True)
    for j in files:
        size1=os.path.getsize(os.path.join(root,j))
        size2=size1/1024/1024
        time=size2/2.6   #分钟数
        #print('{0:-<40}\t\t\t\t{1:>25}\t{2:>20} '.format(j,'size='+str(round(size2))+'MB',format(time,'.1f')+'min'))  #对不齐是因为汉字比较宽
        print('{0:-<{length}}{1:->20}{2:->15}'.format(j,'size='+str(round(size2))+'MB',format(time,'.1f')+'min',length=len(j)+45-len(j.encode('GBK'))))
        tot+=time
print('total time : %.1f h'% (tot/60))




#print('{0:-<{length}}{1:->20}{2:->15}'.format(j,'size='+str(round(size2))+'MB',format(time,'.1f')+'min',length=len(j)+45-len(j.encode('GBK'))))
#关键就是上面这一行代码，巧妙地利用format中的length,并将length通过{length}传入格式串中


